package com.zhongketech.sunflower.adapter;

import java.util.List;

import com.zhongketech.sunflower.R;
import com.zhongketech.sunflower.transport.model.Times;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class TimebucketInfoAdapter extends  ListAdapter{

	public TimebucketInfoAdapter(Context context, List<Times> list) {
		super(context, list);
		mContext = context;
		mDataList = list;
	}

	@Override
	protected View createViewItem(int position, View convertView, ViewGroup group) {
		ViewHolder viewHolder = null;
		if (null == convertView) {
			viewHolder = new ViewHolder();
			convertView = View.inflate(mContext, R.layout.timebucket_control_info_item, null);
			viewHolder.timebucket = (TextView) convertView.findViewById(R.id.timebucket);
			viewHolder.time = (TextView) convertView.findViewById(R.id.modify_time);
			viewHolder.timebucketBottomLine = convertView.findViewById(R.id.timebucketBottomLine);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Times timeItem = (Times) getItem(position);
		viewHolder.time.setText(timeItem.getStart_at()/60+":"+timeItem.getStart_at()%60+" - "+timeItem.getEnd_at()/60+":"+timeItem.getEnd_at()%60);

		if (position == 0) {
			viewHolder.timebucket.setVisibility(View.VISIBLE);
		}
		if ((position + 1) == getCount()) {
			viewHolder.timebucketBottomLine.setVisibility(View.INVISIBLE);
		} else {
			viewHolder.timebucketBottomLine.setVisibility(View.VISIBLE);
		}

		return convertView;
	}

	public class ViewHolder {
		TextView timebucket;
		TextView time;
		View timebucketBottomLine;
	}


}
